﻿using System;



class VariationsOfKElements
{
    //Exercise 20.
    //Write a program that reads two numbers N and K and generates all the variations of K elements from the set [1..N]. 
    //Example: N = 3, K = 2 -> {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}

    static int N;
    static int K;
    static int[] arrayK;

    static void Main()
    {
        Console.Write("Enter N: ");
        N = int.Parse(Console.ReadLine());
        Console.Write("Enter K: ");
        K = int.Parse(Console.ReadLine());
       
        //create a new array of K elements
        int[] array = new int[K];        
        
        NestedArrays(array, 0);        
    }

    private static void PrintArray(int[] arrayK)
    {
        for (int i = 0; i < arrayK.Length; i++)
        {
            Console.Write(arrayK[i] + " ");
        }
        Console.WriteLine();
    }

    static void NestedArrays(int[] arrayK, int currentArray)
    {
        if (currentArray == arrayK.Length)
        {
            PrintArray(arrayK);
           
        }
        else
        {
            for (int counter = 1; counter <= N; counter++)
            {
                arrayK[currentArray] = counter;
                NestedArrays(arrayK, currentArray + 1);
            }
        }        
    }
}

